{ INFORMATICS.MCCME.RU
  Problem statement: http://informatics.mccme.ru/moodle/mod/statements/view3.php?chapterid=755
  Verdict: Accepted
}
uses SysUtils, Math;
 
var
   i,n,q,k:longint;
   a:array[0..100010] of longint;
 
procedure siftup(i:longint);
var t:longint;
begin
while (i>1) and (a[i div 2]<a[i]) do begin
  t:=a[i];
  a[i]:=a[i div 2];
  a[i div 2]:=t;
  i:=i div 2;
end;
end;
 
procedure insert(v:longint);
begin
inc(n);
a[n]:=v;
siftup(n);
end;
 
procedure siftdown(i:longint);
var j,t:longint;
begin
while 2*i<=n do begin
  j:=i;
  if a[2*i]>a[j] then j:=2*i;
  if (2*i+1<=n) and (a[2*i+1]>a[j]) then j:=2*i+1;
  if i<j then begin
    t:=a[i];
    a[i]:=a[j];
    a[j]:=t;
    i:=j;
  end else break;
end;
end;
 
function ex_min:longint;
begin
result:=a[1];
a[1]:=a[n];
dec(n);
siftdown(1);
end;
 
begin
assign(input,'input.txt');
assign(output,'output.txt');
reset(input);
rewrite(output);
fillchar(a,sizeof(a),0);
read(q);
n:=0;
for i:=1 to q do begin
    read(k);
    if k=1 then writeln(ex_min) else begin
       read(k);
       insert(k);
    end;
end;
end.